//
//  SAPHotForumTableViewCell.m
//  CarsHome
//
//  Created by dapeng on 15/12/7.
//  Copyright © 2015年 dapeng. All rights reserved.
//

#import "SAPHotForumTableViewCell.h"
#import "Theme-PrefixHeader.pch"
@implementation SAPHotForumTableViewCell
- (void)dealloc {
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.title = [[UILabel alloc] init];
        self.bbsname = [[UILabel alloc] init];
        self.replycounts = [[UILabel alloc] init];
        self.forumPIc = [[UIImageView alloc] init];
        self.lastreplydate = [[UILabel alloc] init];
        [_lastreplydate release];
        [_forumPIc release];
        [_title release];
        [_bbsname release];
        [_replycounts release];
        [self addSubview:self.title];
        [self addSubview:self.bbsname];
        [self addSubview:self.replycounts];
        [self addSubview:self.forumPIc];
        [self addSubview:self.lastreplydate];
        [_lastreplydate release];
        [_forumPIc release];
        [_replycounts release];
        [_title release];
        [_bbsname release];
    }return self;
}


- (void)layoutSubviews {
    [super layoutSubviews];
    CGFloat height = [self getHeightWithText:_title.text withFont:15];
    CGFloat bbsWidth = [self getWidthWithText:_bbsname.text withFont:12];
    CGFloat dateWidth = [self getWidthWithText:_lastreplydate.text withFont:12];
    self.title.frame = CGRectMake(10, 20, SCREEN_SIZE.width - 80, height);
    self.bbsname.frame = CGRectMake(10, height + 40, bbsWidth, 20);
    self.lastreplydate.frame = CGRectMake(bbsWidth + 15, height + 40, dateWidth, 20);
    self.forumPIc.frame = CGRectMake(bbsWidth + 20 + dateWidth , height + 40, 15, 15);
    self.replycounts.frame = CGRectMake(SCREEN_SIZE.width - 60, height + 40, 50, 20);
    
}

- (void)setTwoModel:(SAPForumTwoModel *)twoModel {
    if (_twoModel != twoModel) {
        [_twoModel release];
        _twoModel = [twoModel retain];
    }
    self.title.text = twoModel.title;
    self.bbsname.text = twoModel.bbsname;
    self.lastreplydate.text = twoModel.lastreplydate;
    self.replycounts.text = [NSString stringWithFormat:@"%@回帖", twoModel.replycounts];
    _replycounts.textAlignment = NSTextAlignmentRight;
    _title.font = [UIFont systemFontOfSize:15];
    _bbsname.font = [UIFont systemFontOfSize:12];
    _lastreplydate.font = [UIFont systemFontOfSize:12];
    _replycounts.font = [UIFont systemFontOfSize:12];
    
    _bbsname.textColor = [UIColor grayColor];
    _lastreplydate.textColor = [UIColor grayColor];
    _replycounts.textColor = [UIColor grayColor];
    
    NSString *str = [NSString stringWithFormat:@"%@", twoModel.ispictopic];
    if ([str isEqualToString:@"1"]) {
        self.forumPIc.image = [UIImage imageNamed:@"hotForum"];
    }else {
        self.forumPIc.image = nil;
    }
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *passWord = [user objectForKey:@"nightModel"];
    
    if (!(passWord == nil) && [passWord isEqualToString:@"day"]) {
        self.backgroundColor = [UIColor colorWithWhite:0.126 alpha:1.000];
        self.title.textColor = RGB(153.0,153.0,153.0,1.0f);;
        self.bbsname.textColor = RGB(153.0,153.0,153.0,1.0f);
        self.replycounts.textColor = RGB(153.0, 153.0, 153.0, 1.0f);
        self.lastreplydate.textColor = RGB(153.0, 153.0, 153.0, 1.0f);
        
    }else{
        self.backgroundColor = [UIColor whiteColor];
        
    }
    
}
- (CGFloat)getWidthWithText:(NSString *)text withFont:(CGFloat)font {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 0) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.width;
}

- (CGFloat)getHeightWithText:(NSString *)text withFont:(CGFloat)font {
    NSDictionary *dic = @{NSFontAttributeName : [UIFont systemFontOfSize:font]};
    CGRect rect = [text boundingRectWithSize:CGSizeMake(0, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return rect.size.height;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
